<template>
	<view>
		<view class="UCenter-bg">
			<view class='avatar'>
				<open-data type="userAvatarUrl"></open-data>
			</view>
			<view class="text-xl margin-top-sm">
				<text>{{member.name}}</text>
			</view>
			<view class="margin-top-xs">
				<text>{{member.mobile}}</text>
			</view>
			<view class="" style="height: 100rpx;">

			</view>
		</view>
		<view class="cu-list menu card-menu margin-top-xl margin-bottom-xl"
			style="border-radius: 0px;margin-top: -50rpx;">
			<template v-if="member.status != 'AUTH_SUCCESS'">
				<view class="cu-item margin-bottom-sm shadow-blur"
					style="border: 1px solid #e3e8f0;border-radius: 3px;">
					<view class="content padding-tb-sm">
						<view>暂无认证账号</view>
						<view class="text-gray text-sm">您当前的账号没有认证主体</view>
					</view>
					<view class="action text-blue text-lg" @click="isrenzheng = true">
						<text class="cuIcon-roundadd margin-right-xs"></text>添加认证
					</view>
				</view>
			</template>
			<template v-else>
				<view class="cu-item margin-bottom-sm shadow-blur"
					style="border: 1px solid #e3e8f0;border-radius: 3px;">
					<view class="content padding-tb-sm">
						<view>账号认证</view>
						<view class="text-gray text-sm">您个人实名已认证，开启文件签署之旅</view>
					</view>
					<navigator open-type="switchTab" url="/pages/member/file" class="action text-lg">
						查看<text class="cuIcon-right margin-right-xs"></text>
					</navigator>
				</view>
			</template>
			<template v-else>
				<view></view>
			</template>


			<view class="cu-item arrow margin-bottom-sm" style="border: 1px solid #e3e8f0;border-radius: 2px;">
				<view class="content" @click="go('qiye')">
					<text class="png cuIcon-taoxiaopu bg-blue"></text>
					<text class="text-black margin-left-xs">企业管理</text>
				</view>
			</view>
			<view class="cu-item arrow margin-bottom-sm" style="border: 1px solid #e3e8f0;border-radius: 2px;">
				<view class="content" @click="go('help')">
					<text class="png cuIcon-question bg-blue"></text>
					<text class="text-black margin-left-xs">帮助中心</text>
				</view>
			</view>
			<view class="cu-item arrow margin-bottom-sm" style="border: 1px solid #e3e8f0;border-radius: 2px;">
				<view class="content" @click="go('setting')">
					<text class="png cuIcon-settings bg-blue"></text>
					<text class="text-black margin-left-xs">设置</text>
				</view>
			</view>
			<view class="cu-item arrow margin-bottom-sm" style="border: 1px solid #e3e8f0;border-radius: 2px;">
				<view class="content" @click="dingyue">
					<text class="png cuIcon-subscription bg-blue"></text>
					<text class="text-black margin-left-xs">订阅消息</text>
				</view>
			</view>
			<!-- <view class="cu-item arrow margin-bottom-sm" style="border: 1px solid #e3e8f0;border-radius: 2px;">
				<view class="content" @click="go('exit')">
					<text class="png cuIcon-exit bg-blue"></text>
					<text class="text-black margin-left-xs">退出关闭</text>
				</view>
			</view> -->
		</view>
		<view class="cu-modal bottom-modal" :class="isrenzheng?'show':''" @click="isrenzheng = false">
			<view class="cu-dialog" @click.stop="">
				<view class="cu-bar bg-white solids-bottom">
					<view class="action" @click="isrenzheng = false">
						<text class="cuIcon-close"></text>
					</view>
					<view class="content text-bold">
						选择认证主体
					</view>
				</view>
				<view class="padding-xl bg-white">
					<view class="cu-list menu-avatar solids radius" @click="go('authurl')"
						v-if="member.status == 'AUTH_FAILURE'">
						<view class="cu-item">
							<view class="cu-avatar round lg" style="background-color: unset;border:1px solid #0081FF">
								<image src="../../static/34.png" mode="" style="width: 68rpx;height: 40rpx;"></image>
							</view>
							<view class="content" style="width: 100%;">
								<view class="text-black text-bold">个人实名认证</view>
								<view class="text-gray text-sm flex">
									<view class="text-cut">
										点击进去“静坐”个人实名认证
									</view>
								</view>
							</view>
						</view>
					</view>

					<view class="cu-list menu-avatar solids radius" @click="go('h5page')">
						<view class="cu-item">
							<view class="cu-avatar round lg" style="background-color: unset;border:1px solid #0081FF">
								<image src="../../static/36.png" mode="" style="width: 68rpx;height: 40rpx;"></image>
							</view>
							<view class="content" style="width: 100%;">
								<view class="text-black text-bold">企业主体认证</view>
								<view class="text-gray text-sm flex">
									<view class="text-cut">
										通过企业实名认证，授权成为企业员工
									</view>
								</view>
							</view>
						</view>
					</view>

				</view>
			</view>
		</view>



		<view class="cu-modal" :class="modalName=='qiye'?'show':''" @tap="hideModal">
			<view class="cu-dialog" @click.stop="">
				<view class="cu-bar bg-white solids-bottom">
					<view class="action" @click="hideModal">
						<text class="cuIcon-close"></text>
					</view>
					<view class="content text-bold">
						我的企业
					</view>
				</view>
				<view class="padding-xs bg-white" style="text-align: left;">
					<view class="cu-list menu">
						<block v-for="(item,index) in member.companies" :key="index">
							<view class="cu-item arrow" @click="go('cxrz',item)">
								<view class="content" style="width: 100%;">
									<view class="text-black text-bold">{{item.name}}
										<text class='cu-tag sm bg-blue' v-if="item.status == 'AUTH_SUCCESS'">认证成功</text>
										<text class='cu-tag sm bg-red' v-else>认证失败</text>
									</view>
								</view>
							</view>
						</block>
					</view>

				</view>
			</view>
		</view>


		<view class="cu-tabbar-height"></view>
		<view class="cu-bar tabbar bg-white shadow foot">
			<navigator class="action" open-type="switchTab" url="/pages/index/index">
				<view class='cuIcon-homefill'></view>
				<view>首页</view>
			</navigator>
			<navigator open-type="switchTab" url="/pages/member/file" class="action">
				<view class='cuIcon-file'></view>
				<view>文件</view>
			</navigator>
			<navigator url="/pages/member/index" class="action">
				<view class='cuIcon-people text-blue'></view>
				<view>我的</view>
			</navigator>
		</view>
	</view>
</template>

<script>
	var that
	export default {
		data() {
			return {
				member: {},
				user: {},
				isrenzheng: false,
				isqiye: false,
				modalName: null,
			}
		},
		onLoad() {
			that = this
			that.$u.post('index/member').then(res => {
				that.user = res
			})
			that.$u.post('qiyue/user').then(res => {
				that.member = res
				let company = []
				for (let i in that.member.companies) {
					company.push(that.member.companies[i].name);
				}
				that.company = company
			})
		},
		methods: {
			dingyue(){
				wx.requestSubscribeMessage({
					tmplIds: ['MFb3FPAFmka9C69W9O2VC35CrwQRX2eBnz7ZICC0Wac'],
					success(res) {
						
					}
				})		
			},
			hideModal(e) {
				this.modalName = null
			},
			go(url,item='') {
				if (!that.user.salesman_mobile) {
					uni.showToast({
						title: '您还未登陆',
						duration: 2000,
						icon: "none",
						success() {
							uni.navigateTo({
								url: '/pages/member/member'
							})
						}
					});
					// that.isrenzheng = true
					return false
				}
				if (url == 'qiye') {
					uni.navigateTo({
						url:'/pages/company/index'
					})
				} else if (url == 'setting') {
					uni.navigateTo({
						url:'/pages/member/setting'
					})
				} else if (url == 'exit') {
					uni.reLaunch({
						url:'/pages/member/login',
						success() {
							uni.clearStorage()
						}
					})
				} else if (url == 'help') {
					uni.navigateTo({
						url:'/pages/index/help'
					})
				} else if (url == 'cxrz') {
					that.$u.post('qiyue/h5page', {
						name: item.name
					}).then(res => {
						if (res.code !== 0) {
							uni.showToast({
								title: res.message,
								duration: 2000,
								icon: "none"
							});
							return false
						}
						uni.navigateTo({
							url: '/pages/center/index?url=' + encodeURIComponent(JSON.stringify(res.authurl))
						})
					})
				} else if (url == 'h5page') {
					if (this.member.status == 'AUTH_FAILURE') {
						uni.showToast({
							title: '您需要先完成个人实名认证',
							duration: 2000,
							icon: "none"
						});
						return false
					}
					uni.showActionSheet({
						itemList: that.company,
						success: function(res) {
							that.$u.post('qiyue/h5page', {
								name: that.company[res.tapIndex]
							}).then(res => {
								if (res.code !== 0) {
									uni.showToast({
										title: res.message,
										duration: 2000,
										icon: "none"
									});
									return false
								}
								uni.navigateTo({
									url: '/pages/center/index?url=' + encodeURIComponent(JSON.stringify(res.authurl))
								})
							})
						},
						fail: function(res) {
							console.log(res.errMsg);
						}
					});
				} else {
					that.$u.post('qiyue/' + url, {}).then(res => {
						uni.navigateTo({
							url: '/pages/center/index?url=' + encodeURIComponent(JSON.stringify(res
								.result))
						})
					})
				}
			}
		}
	}
</script>

<style>
	.UCenter-bg {
		background-image: url(https://wx.qdhansen.com/images/bg.png);
		background-size: cover;
		height: 380rpx;
		display: flex;
		justify-content: center;
		padding-top: 40rpx;
		overflow: hidden;
		position: relative;
		flex-direction: column;
		align-items: center;
		color: #fff;
		font-weight: 300;
		text-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
	}

	.UCenter-bg text {
		opacity: 0.8;
	}

	.avatar {
		width: 150rpx;
		height: 150rpx;
		overflow: hidden;
		border-radius: 50%;
	}
</style>
